import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:插入排序
 * User:龙宝
 * Date:2023-11-12
 * Time:15:47
 */
public class InsertSort {
    public static void main(String[] args) {
        int[] arr = {9,4,1,2,0,6,5,3,10,7,8};
        insertSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    private static void insertSort(int[] arr) {
        for(int i = 1;i<arr.length;i++) {
            int start = arr[i];
            int j = i-1;
            while (j >= 0 && arr[j] > start) {
                arr[j+1] = arr[j--];
            }
            arr[j+1] = start;
        }
    }
}
